package com.javaweb.dao.impl;

import com.javaweb.dao.CategoryDao;
import com.javaweb.model.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class CategoryDaoImpl implements CategoryDao {
    @Autowired
    JdbcTemplate jdbcTemplate ;

    @Override
    public int insert(Category category) {
        String sql = "INSERT INTO tb_category (id, name, `order`, parent_id, create_time, udpate_time) VALUES (?, ?, ?, ?, ?, ?)";
        Object [] args = new Object[]{
                category.getId(),
                category.getName(),
                category.getOrder(),
                category.getParentId(),
                new java.sql.Date(category.getCreateTime().getTime()),
                new java.sql.Date(category.getUpdateTime().getTime())};
        return jdbcTemplate.update(sql, args);
    }
}